home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / misc / emu / QDOS2.lha / QLsource / ROMsrc / SYS / DBUGCODE_asm < prev    next >
Text File  |  1995-08-30  |  20KB  |  1,014 lines

  1. */beginfile DBUGCODE_asm
  2. ; --------------------------------------------------------------
  3. ; DBUGCODE_asm - QDOS debugging routines
  4. ;          - last modified 30/08/95
  5. ; QDOS-Amiga sources by Rainer Kowallik
  6. ;  ...latest changes by Mark J Swift
  7. ; --------------------------------------------------------------
  8. ;*/beginoverlay
  9.  
  10. ; --------------------------------------------------------------
  11. ; main interrupt server
  12. ; --------------------------------------------------------------
  13. QL_MAIN_INT:
  14.     MOVEM.L    D7/A5/A6,-(A7)
  15.     MOVEA.L    A7,A5
  16.     move.l    a5,d7        ; calculate SV_BASE
  17.     andi.w    #-$8000,d7
  18.     move.l    d7,a6
  19.     move.b    PC_INTR,d7
  20.     lsr.b    #4,d7
  21.     bcs    L00900        ; Vertical blank
  22.     lsr.b    #1,d7
  23.     bcc.s    L003B6
  24.  
  25. ; --------------------------------------------------------------
  26. ; external interrupt
  27.  
  28.     MOVEM.L    D0-D6/A0-A4,-(A7)
  29.     MOVEQ    #0,D0
  30.     MOVEA.L    SV_I2LST(A6),A0    ; pointer to list of
  31.                 ; interrupt 2 drivers
  32.     BSR    EXEC_TSK     ; execute polled task
  33.     MOVEM.L    (A7)+,D0-D6/A0-A4
  34.     BRA.S    L003B6
  35.  
  36. ; --------------------------------------------------------------
  37. ;  Common return for Most system manager traps
  38.  
  39. RET_CLD0:
  40.     MOVEQ    #0,D0
  41. L003A6:
  42. RET_TRAP:
  43.     BTST    #5,$C(A7)    ; was it supervisor mode ?
  44.     BNE.S    L003B6
  45.     TST.W    SV_POLLM(A6)    ; count of poll interrupts
  46.                 ; missed
  47.     BNE    L00936
  48. L003B6:
  49.     MOVEM.L    (A7)+,D7/A5/A6
  50.     RTE
  51.  
  52. ; --------------------------------------------------------------
  53. ;  Execute polled task
  54.  
  55. L00A9E:
  56. EXEC_TSK:
  57.     MOVE.W    D0,-(A7)
  58. L00AA0:
  59.     MOVEA.L    A0,A3
  60.     ADDA.W    (A7),A3        ;!!! word adding may cause
  61.                 ; errors !!!
  62.     MOVE.L    A0,-(A7)
  63.     BEQ.S    L00ABC
  64.     MOVE.W    D3,-(A7)
  65.     ANDI.W    #$7F,D3
  66.     MOVEA.L    4(A0),A0     ; A0=address of task
  67.     JSR    (A0)
  68.     MOVE.W    (A7)+,D3
  69.     MOVEA.L    (A7)+,A0
  70.     MOVEA.L    (A0),A0
  71.     BRA.S    L00AA0
  72. L00ABC:
  73.     ADDQ.L    #6,A7
  74.     RTS
  75.  
  76. ; --------------------------------------------------------------
  77. ;  TRAP #0 - Enter supervisor mode
  78. ; --------------------------------------------------------------
  79. L00318:
  80. TRAP0    bset    #5,(a7)
  81.     rte
  82.  
  83. ; --------------------------------------------------------------
  84. TRAP1    BSR.S    INI_A5A6
  85.     BRA    DO_TRAP1
  86. TRAP2    BSR.S    INI_A5A6
  87.     BRA    DO_TRAP2
  88. TRAP3    BSR.S    INI_A5A6
  89.     BRA    DO_TRAP3
  90. TRAP4    BSR.S    INI_A5A6
  91.     BRA    DO_TRAP4
  92.  
  93. ; --------------------------------------------------------------
  94. ; Initialize A5 and A6
  95.  
  96. L00336:
  97. INI_A5A6:
  98.     SUBQ.W    #8,A7
  99.     MOVE.L    8(A7),-(A7)
  100.     MOVEM.L    D7/A5/A6,4(A7)
  101.     LEA    4(A7),A5     ; A5 points saved D7,A5,A6
  102.     move.l    a5,d7        ; calculate SV_BASE
  103.     andi.w    #-$8000,d7
  104.     move.l    d7,a6
  105.     MOVEQ    #$7F,D7        ; Registers D7,A5,A6
  106.     AND.L    D7,D0
  107.     RTS
  108.  
  109. ; --------------------------------------------------------------
  110. ;  exceptions that are not handled by user vector
  111. ; --------------------------------------------------------------
  112. BUSERR:
  113.     ori    #$0700,sr    ; mask out all interrupts
  114.  
  115.     bsr    CHK6800X     ; use special 680X0 code?
  116.     bne    TRP0X0
  117.  
  118.     bsr    XTRA
  119.     addq.l    #8,a7        ; dump 68000/008 extra info
  120.  
  121.     bsr    STK_REGS
  122.     moveq    #$08,d7        ; vector offset
  123.  
  124.     bsr    CH_ZERO
  125.     bra    PRTVCTR
  126.  
  127. ; --------------------------------------------------------------
  128. TRPOTHER:
  129.     ori    #$0700,sr    ; mask out all interrupts
  130.  
  131.     bsr    CHK6800X     ; use special 680X0 code?
  132.     bne    TRP0X0
  133.  
  134. ILLEG_INT:
  135.     rte            ; otherwise ignore exception
  136.  
  137. ; --------------------------------------------------------------
  138. ;  special cases of exceptions handled by user vector
  139. ; --------------------------------------------------------------
  140. TAS_EMU:
  141.  
  142. ; Provide emulation of TAS instruction for machines that
  143. ; cannot handle READ-MODIFY-WRITE.
  144.  
  145. ; The user must first replace any TAS (An) / TAS d(An)
  146. ; / TAS $absolute.L by the corresponding line F command
  147. ; (with co-processor ID=7).
  148.  
  149. ; The following code will then emulate the TAS command with
  150. ; the appropriate TST.B ?? and BSET #7,?? instruction pair.
  151.  
  152.     ori    #$0700,sr    ; mask out all interrupts
  153.  
  154.     movem.l    d0-d1/a0-a1,-(a7) ; save regs
  155.  
  156.     move.l    $12(a7),a0    ; addr of last instruction
  157.     move.w    (a0)+,d0     ; get instruction
  158.  
  159.     move.w    d0,d1
  160.     and.w    #$FE00,d0
  161.  
  162.     cmp.w    #$AE00,d0    ; v3.23 or later TAS?
  163.     beq.s    TAS_VALID
  164.  
  165.     cmp.w    #$FE00,d0    ; v3.20-v3.22 TAS?
  166.     beq.s    TAS_VALID
  167.  
  168.     cmp.w    #$F000,d0    ; pre v3.20 TAS?
  169.     bne.s    TAS_SKIP
  170.  
  171. TAS_VALID:
  172.     lea    MODCODE,a1    ; put addr of self-mod code
  173.     move.l    a1,$12(a7)    ; onto stack ready for RTE
  174.  
  175.     move.w    d1,d0        ; restore instruction
  176.     AND.W    #$003F,D0    ; only effective address
  177.  
  178.     MOVE.W    D0,D1
  179.     OR.W    #$4A00,D1    ; make TST.B ? instr.
  180.     move.w    d1,(a1)+     ; put TST instr in place
  181.  
  182.     or.w    #$08C0,d0    ; make BSET #,? instr.
  183.  
  184.     AND.W    #$0038,D1    ; get EA mode
  185.  
  186.     CMP.W    #$0028,D1    ; ARI with displacement ?
  187.     BEQ.S    TAS_ARID
  188.  
  189.     CMP.W    #$0030,D1    ; ARI with index ?
  190.     BEQ.S    TAS_ARID     ; treat as with displacement
  191.                 ; only (should not happen)
  192.  
  193.     CMP.W    #$0038,D1    ; absolute.L ?
  194.     bne.s    TAS_ARI        ; no, treat all other modes
  195.                 ; as ARI
  196.  
  197.     cmp.w    #$08F9,d0    ; really absolute.L ?
  198.     bne.s    TAS_ARID     ; no, treat as ARI+disp.
  199.  
  200. TAS_ABSL:
  201.     move.l    (a0),(a1)+    ; copy long data field
  202.     move.w    d0,(a1)+     ; store BSET instruction
  203.     move.w    #7,(a1)+     ; put bit # to set in place
  204.     move.l    (a0)+,(a1)+    ; copy long data field
  205.     bra.s    TAS_DOIT
  206.  
  207. TAS_ARID:
  208.     move.w    (a0),(a1)+    ; copy word data field
  209.     move.w    d0,(a1)+     ; store BSET instruction
  210.     move.w    #7,(a1)+     ; put bit # to set in place
  211.     move.w    (a0)+,(a1)+    ; copy word data field
  212.     bra.s    TAS_DOIT
  213.  
  214. TAS_ARI:
  215.     move.w    d0,(a1)+     ; store BSET instruction
  216.     move.w    #7,(a1)+     ; put bit # to set in place
  217.  
  218. TAS_DOIT:
  219.     bra.s    MSR_JMP
  220.  
  221. TAS_SKIP:
  222.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  223.     bra    ILL_INST
  224.  
  225. ; --------------------------------------------------------------
  226. MSR_EMU:
  227.  
  228. ; The following code traps the priviledge exception caused by
  229. ; processing the move sr,<aywhere> instruction in user mode on
  230. ; 680X0 processors, and executes equivalent code.
  231.  
  232. ; The move sr,<anywhere> instruction is not priviledged on the
  233. ; 68000/68008 processors and is used extensively in the pointer
  234. ; environment while in user mode. In later processors the
  235. ; instruction can only be executed in supervisor mode.
  236.  
  237.     ori    #$0700,sr    ; mask out all interrupts
  238.  
  239.     movem.l    d0-d1/a0-a1,-(a7) ; save regs
  240.  
  241.     move.l    $12(a7),a0    ; addr of last instruction
  242.     move.w    (a0)+,d0     ; get instruction
  243.  
  244.     moveq    #0,d1
  245.     move.w    d0,d1
  246.     and.w    #$FFC0,d0
  247.     cmp.w    #$40C0,d0    ; move sr,<?> instruction?
  248.     bne.s    MSR_SKIP     ; ...no, so exit
  249.  
  250.     move.w    $10(a7),d0    ; get sr
  251.     move.l    usp,a1
  252.     move.w    d0,-(a1)     ; push sr onto user stack
  253.     move.l    a1,usp
  254.  
  255.     lea    MODCODE,a1    ; put addr of self-mod code
  256.     move.l    a1,$12(a7)    ; onto stack ready for RTE
  257.  
  258.     move.w    d1,d0
  259.     andi.w    #$0038,d0    ; get effective address
  260.     beq.s    MSR_DATA     ; branch if move sr,dn
  261.                 ; (special case)
  262.  
  263.     andi.w    #$0007,d1    ; get register
  264.     lsl.w    #6,d1        ; shift
  265.     or.w    d0,d1        ; add in EA
  266.     lsl.w    #3,d1        ; shift
  267.     or.w    #$301F,d1    ; make move.w (a7)+,? instr.
  268.     move.w    d1,(a1)+     ; put instr in place
  269.  
  270.     cmp.w    #$0028,d0    ; ARI with displacement ?
  271.     beq.s    MSR_ARID
  272.  
  273.     cmp.w    #$0030,d0    ; ARI with index ?
  274.     beq.s    MSR_SKIP     ; sorry, can't handle yet!
  275.  
  276.     cmp.w    #$0038,d0    ; absolute.L ?
  277.     bne.s    MSR_ARI        ; no, treat all other modes
  278.                 ; as ARI
  279.  
  280.     cmp.w    #$33DF,d1    ; really absolute.L ?
  281.     bne.s    MSR_JMP        ; no, treat as ARI+disp.
  282.  
  283. MSR_ABSL:
  284.     move.l    (a0)+,(a1)+    ; copy long data field
  285.     bra.s    MSR_JMP
  286.  
  287. MSR_ARID:
  288.     move.w    (a0)+,(a1)+    ; copy word data field
  289.  
  290. MSR_ARI:
  291.     bra.s    MSR_JMP
  292.  
  293. MSR_DATA:
  294.     move.w    #$4C9F,(a1)+    ; make movem.w (a7)+ instr
  295.  
  296.     andi.w    #$0007,d1    ; get register #
  297.     moveq    #0,d0
  298.     bset    d1,d0        ; set correct bit for dn
  299.     move.w    d0,(a1)+     ; complete movem.w (a7)+,dn
  300.  
  301. MSR_JMP:
  302.     move.w    #$4EF9,(a1)+    ; make JMP instruction
  303.     move.l    a0,(a1)+     ; jump behind MSR instr
  304.  
  305. MSR_XIT:
  306.     bsr    CLRALL        ; ...just in case
  307.  
  308.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  309.  
  310.     rte            ; perform operation
  311.  
  312. MSR_SKIP:
  313.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  314.     bra.s    PRIV_ERR
  315.  
  316. ; --------------------------------------------------------------
  317. ;  Redirect other exceptions thro' possible user table
  318. ; --------------------------------------------------------------
  319. TRAPRDIR:
  320. ADR_ERR:
  321.     BSR.S    TRAPTRAP
  322. ILL_INST:
  323.     BSR.S    TRAPTRAP
  324. ZERO_DIV:
  325.     BSR.S    TRAPTRAP
  326. CHK_INST:
  327.     BSR.S    TRAPTRAP
  328. TRAPV_INst:
  329.     BSR.S    TRAPTRAP
  330. PRIV_ERR:
  331.     BSR.S    TRAPTRAP
  332. TRACE:
  333.     BSR.S    TRAPTRAP
  334. NMI_INT:
  335.     BSR.S    TRAPTRAP
  336. TRAP5:
  337.     BSR.S    TRAPTRAP
  338. TRAP6:
  339.     BSR.S    TRAPTRAP
  340. TRAP7:
  341.     BSR.S    TRAPTRAP
  342. TRAP8:
  343.     BSR.S    TRAPTRAP
  344. TRAP9:
  345.     BSR.S    TRAPTRAP
  346. TRAP10:
  347.     BSR.S    TRAPTRAP
  348. TRAP11:
  349.     BSR.S    TRAPTRAP
  350. TRAP12:
  351.     BSR.S    TRAPTRAP
  352. TRAP13:
  353.     BSR.S    TRAPTRAP
  354. TRAP14:
  355.     BSR.S    TRAPTRAP
  356. TRAP15:
  357.     BSR.S    TRAPTRAP
  358.  
  359. ; --------------------------------------------------------------
  360. ;  default exception/trap table
  361. ; --------------------------------------------------------------
  362. TRAPTAB:
  363.         DC.L    ADRERR-ORG0
  364.         DC.L    ILLINS-ORG0
  365.         DC.L    ZERODV-ORG0
  366.         DC.L    CHKR-ORG0
  367.         DC.L    TRAPVR-ORG0
  368.         DC.L    PRIVR-ORG0
  369.         DC.L    TRACET-ORG0
  370.         DC.L    NMI_NEW-ORG0
  371.         DC.L    TRAPR-ORG0
  372.         DC.L    TRAPR-ORG0
  373.         DC.L    TRAPR-ORG0
  374.         DC.L    TRAPR-ORG0
  375.         DC.L    TRAPR-ORG0
  376.         DC.L    TRAPR-ORG0
  377.         DC.L    TRAPR-ORG0
  378.         DC.L    TRAPR-ORG0
  379.         DC.L    TRAPR-ORG0
  380.         DC.L    TRAPR-ORG0
  381.         DC.L    TRAPR-ORG0
  382.  
  383. ; --------------------------------------------------------------
  384. ;  transfer execution to user or default exception handler
  385. ; --------------------------------------------------------------
  386. TRAPTRAP:
  387.     move.l    a6,-(a7)     ; save a6
  388.     exg    d7,a6        ; save d7
  389.     move.l    a7,d7
  390.     andi.w    #-$8000,d7    ; calc sys vars in a6
  391.     exg    d7,a6        ; restore d7
  392.     tst.l    $50(a6)        ; is there a redirection tbl
  393.     bne.s    TRPCONT1     ; ..yes, use it.
  394.  
  395.     move.l    #(TRAPTAB-ORG0)-2*((TRAPRDIR-ORG0)+2),a6 ; default
  396.     bra.s    TRPCONT3
  397. TRPCONT1:
  398.     move.l    $50(a6),a6
  399. TRPCONT2:
  400.     suba.l    #2*(TRAPRDIR-ORG0-$28),a6 ; compensate for
  401.                         ; different table psn
  402. TRPCONT3:
  403.     adda.l    4(a7),a6
  404.     adda.l    4(a7),a6     ; address of long vector
  405.     move.l    (a6),4(a7)    ; stack routine address
  406.     move.l    (a7)+,a6     ; restore a6
  407.     rts            ; call routine
  408.  
  409. ; --------------------------------------------------------------
  410. ; Default user exception handlers
  411.  
  412. ADRERR:
  413.     ori    #$0700,sr    ; mask out all interrupts
  414.  
  415.     bsr    CHK6800X     ; use special 680X0 code?
  416.     bne    TRP0X0
  417.  
  418.     bsr    XTRA
  419.     addq.l    #8,a7        ; dump 68000/008 extra info
  420.  
  421.     bsr    STK_REGS
  422.     moveq    #$0C,d7        ; vector offset
  423.  
  424.     bsr    CH_ZERO
  425.     bra    PRTVCTR
  426.  
  427. ; --------------------------------------------------------------
  428. ILLINS:
  429.     ori    #$0700,sr    ; mask out all interrupts
  430.  
  431.     movem.l    d0-d1/a0-a1,-(a7) ; save regs
  432.  
  433.     move.l    $12(a7),a0    ; addr of last instruction
  434.     move.w    (a0)+,d0     ; get instruction
  435.  
  436.     move.w    d0,d1
  437.     andi.w    #$F138,d0
  438.     cmpi.w    #$0108,d0
  439.     beq    MOVP        ; branch if due to MOVEP
  440.  
  441.     move.w    d1,d0
  442.     andi.w    #$F000,d0
  443.  
  444.     cmp.w    #$A000,d0
  445.     beq.s    ALINE        ; branch if A-LINE instruction
  446.  
  447.     cmp.w    #$F000,d0
  448.     beq.s    FLINE        ; branch if F-LINE instruction
  449.  
  450.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  451.  
  452.     bsr    CHK6800X     ; use special 680X0 code?
  453.     bne    TRP0X0
  454.  
  455.     bsr    STK_REGS
  456.     moveq    #$10,d7        ; vector offset
  457.  
  458. ILLINS1:
  459.     bsr    CH_ZERO
  460.  
  461.     LEA    TXTC(PC),A1
  462.     bsr    IOSTRG        ; print err message
  463.  
  464.     move.l    $42(a7),a1
  465.     move.w    (a1),d0
  466.     bsr    HEX10
  467.  
  468.     lea    TXTSPC(pc),a1
  469.     bsr    IOSTRG
  470.  
  471.     bra    PRTVCTR
  472.  
  473. ; --------------------------------------------------------------
  474. MOVP:
  475.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  476.  
  477.     bsr    STK_REGS
  478.     jsr    _moveperipheral-ORG0
  479.     bra    TIDYUP
  480.  
  481. ; --------------------------------------------------------------
  482. ALINE:
  483.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  484.  
  485.     bsr    CHK6800X     ; use special 680X0 code?
  486.     bne    TRP0X0
  487.  
  488.     bsr    STK_REGS
  489.     moveq    #$28,d7
  490.  
  491.     bra    ILLINS1
  492.  
  493. ; --------------------------------------------------------------
  494. FLINE:
  495.     movem.l    (a7)+,d0-d1/a0-a1 ; restore registers
  496.  
  497.     bsr    CHK6800X     ; use special 680X0 code?
  498.     bne    TRP0X0
  499.  
  500.     bsr    STK_REGS
  501.     moveq    #$2C,d7
  502.  
  503.     bra    ILLINS1
  504.  
  505. ; --------------------------------------------------------------
  506. ZERODV:
  507.     ori    #$0700,sr    ; mask out all interrupts
  508.  
  509.     bsr    CHK6800X     ; use special 680X0 code?
  510.     bne    TRP0X0
  511.  
  512.     bsr    STK_REGS
  513.     moveq    #$14,d7        ; vector offset
  514.  
  515.     bsr    CH_ZERO
  516.     bra    PRTVCTR
  517.  
  518. ; --------------------------------------------------------------
  519. CHKR:
  520.     ori    #$0700,sr    ; mask out all interrupts
  521.  
  522.     bsr    CHK6800X     ; use special 680X0 code?
  523.     bne    TRP0X0
  524.  
  525.     bsr    STK_REGS
  526.     moveq    #$18,d7        ; vector offset
  527.  
  528.     bsr    CH_ZERO
  529.     bra    PRTVCTR
  530.  
  531. ; --------------------------------------------------------------
  532. TRAPVR:
  533.     ori    #$0700,sr    ; mask out all interrupts
  534.  
  535.     bsr    CHK6800X     ; use special 680X0 code?
  536.     bne    TRP0X0
  537.  
  538.     bsr    STK_REGS
  539.     moveq    #$1C,d7        ; vector offset
  540.  
  541.     bsr    CH_ZERO
  542.     bra    PRTVCTR
  543.  
  544. ; --------------------------------------------------------------
  545. PRIVR:
  546.     ori    #$0700,sr    ; mask out all interrupts
  547.  
  548.     bsr    CHK6800X     ; use special 680X0 code?
  549.     bne    TRP0X0
  550.  
  551.     bsr    STK_REGS
  552.     moveq    #$20,d7        ; vector offset
  553.  
  554.     bsr    CH_ZERO
  555.     bra    PRTVCTR
  556.  
  557. ; --------------------------------------------------------------
  558. NMI_NEW:
  559.     ori    #$0700,sr    ; mask out all interrupts
  560.  
  561.     bsr    CH_ZERO
  562.     bra    DEAD        ; warm-start into BASIC
  563.  
  564. ; --------------------------------------------------------------
  565. TRACET:
  566.     ori    #$0700,sr    ; mask out all interrupts
  567.  
  568.     bsr    CHK6800X     ; use special 680X0 code?
  569.     bne    TRP0X0
  570.  
  571.     bsr    STK_REGS
  572.     moveq    #$24,d7        ; vector offset
  573.  
  574.     bsr    CH_ZERO
  575.     bra    PRTVCTR
  576.  
  577. ; --------------------------------------------------------------
  578. TRAPR:
  579.     rte            ; ignore undefined TRAP #s
  580.  
  581. ; --------------------------------------------------------------
  582. XTRA:
  583.     movem.l    d0-d7/a0-a6,-(a7) ; save regs
  584.  
  585.     bsr    CH_ZERO
  586.  
  587.     move.w    $40(a7),d0
  588.     lea    TXTR(PC),a1
  589.     btst    #4,d0
  590.     beq.s    XTRA1
  591.     lea    TXTW(PC),a1
  592. XTRA1:
  593.     bsr    IOSTRG        ; R/W
  594.  
  595.     lea    TXTI(PC),a1
  596.     btst    #3,d0
  597.     beq.s    XTRA2
  598.     lea    TXTX(PC),a1
  599. XTRA2:
  600.     bsr    IOSTRG        ; instruction/exception
  601.  
  602.     andi.w    #$7,d0
  603.     lsl.w    #1,d0
  604.     lea    TXTTBL(PC),a1
  605.     move.w    0(a1,d0.w),d0
  606.     lea    TXTUDS(PC),a1
  607.     lea    0(a1,d0.w),a1
  608.     bsr    IOSTRG        ; address space
  609.  
  610.     lea    TXTG(PC),a1
  611.     bsr    IOSTRG
  612.  
  613.     move.l    $42(a7),d0
  614.     bsr    HEX20        ; address
  615.  
  616.     lea    TXTH(PC),a1
  617.     bsr    IOSTRG
  618.  
  619.     move.w    $46(a7),d0
  620.     bsr    HEX10        ; instruction
  621.  
  622.     lea    TXTSPC(pc),a1
  623.     bsr    IOSTRG
  624.  
  625.     movem.l    (a7)+,d0-d7/a0-a6 ; restore regs
  626.  
  627.     rts
  628.  
  629. ; --------------------------------------------------------------
  630. ; 68010 '020 '030 '040 exception handler
  631.  
  632. TRP0X0:
  633.     bsr    STK_REGS
  634.     move.w    $46(a7),d7
  635.     andi.w    #$0FFF,d7    ; vector offset
  636.  
  637. ; find ID for channel zero
  638.  
  639.     bsr    CH_ZERO
  640.  
  641. ; print format code and stack frame
  642.  
  643.     cmp.w    #$24,d7
  644.     beq.s    PRTVCTR        ; skip if TRACE
  645.  
  646.     lea    TXTFMSG(pc),a1    ; "Format code: "
  647.     bsr    IOSTRG
  648.  
  649.     move.w    $46(a7),d0
  650.     rol.w    #4,d0
  651.     andi.w    #$000F,d0
  652.     bsr    HEX04        ; print actual code
  653.  
  654.     lsl.w    #1,d0
  655.     lea    TXTFTBL(PC),a1
  656.     move.w    0(a1,d0.w),d0
  657.     lea    TXT0000(PC),a1
  658.     lea    0(a1,d0.w),a1
  659.     bsr    IOSTRG        ; print stack frame type
  660.  
  661.     lea    TXTSPC(pc),a1
  662.     bsr    IOSTRG
  663.  
  664. ; --------------------------------------------------------------
  665. ; print EXCEPTION VECTOR (now in d7)
  666.  
  667. PRTVCTR:
  668.     cmp.w    #$24,d7
  669.     beq.s    PRTSR        ; skip if TRACE
  670.  
  671.     lea    TXTTMSG(pc),a1
  672.     bsr    IOSTRG        ; print "VECTOR OFFSET "
  673.  
  674.     move.l    d7,d0
  675.     bsr    HEX10
  676.  
  677.     lea    TXTSPC(pc),a1
  678.     bsr    IOSTRG
  679.  
  680. ; print exception - if known
  681.  
  682.     cmp.w    #$30,d7
  683.     bge.s    PRTSR
  684.  
  685.     move.l    d7,d0
  686.     lsr.w    #1,d0
  687.     lea    TXTTTBL(PC),a1
  688.     move.w    0(a1,d0.w),d0
  689.     lea    TXT00(PC),a1
  690.     lea    0(a1,d0.w),a1
  691.     bsr    IOSTRG        ; print exception
  692.  
  693.     lea    TXTSPC(pc),a1
  694.     bsr    IOSTRG
  695.  
  696. ; print Status Register
  697.  
  698. PRTSR:
  699.     LEA    TXTSR(PC),A1
  700.     BSR    IOSTRG
  701.  
  702.     MOVE.W    $40(a7),d0
  703.     BSR    HEX10        ; print SR
  704.  
  705. ; print Program Counter
  706.  
  707.     LEA    TXTPC(PC),A1
  708.     BSR    IOSTRG
  709.  
  710.     MOVE.L    $42(a7),d0
  711.     BSR    HEX20        ; print PC
  712.  
  713.     lea    TXTSPC(pc),a1
  714.     bsr    IOSTRG
  715.  
  716.     move.l    a7,a2        ; address of regs on stack
  717.  
  718. ; print register contents to screen
  719.  
  720.     lea    REGSTK,a3
  721.     move.l    d0,(a3)+
  722.     move.w    (a3)+,d3
  723.  
  724.     lea    TXTREGD(pc),a1
  725.     move.l    a1,d2
  726.     bsr    REGPRT
  727.  
  728.     lea    TXTREGA(pc),a1
  729.     move.l    a1,d2
  730.     bsr    REGPRT
  731.  
  732.     lea    TXTRTN(pc),a1
  733.     bsr    IOSTRG
  734.  
  735.     move.w    $40(a7),-66(a3)
  736.  
  737. ; check for trace
  738.  
  739.     cmp.w    #$24,d7
  740.     beq    NOTDEAD        ; TRACE is not deadly
  741.  
  742. ; exit to BASIC
  743.  
  744. DEAD:
  745.     bclr    #7,JB_RELA6(a4)    ; addresses not a6 relative
  746.  
  747.     move.l    BV_CHBAS(a6),d1    ; get ptr to BASICs # table
  748.     move.l    0(a6,d1.l),d0    ; get ID for #0
  749.     blt.s    DO_WINDO     ; branch if #0 is closed
  750.  
  751.     move.l    d0,a0        ; move ID to a0
  752.     bsr    CH_KEYQ        ; check if chan has a key Q
  753.     bne.s    REL_BAS        ; ...branch if so
  754.  
  755.     move.l    #-1,0(a6,d1.l)    ; otherwise close BASICs' #0
  756.     andi    #$F8FF,sr    ; enable interrupts
  757.     moveq    #IO.CLOSE,d0
  758.     trap    #2        ; close channel
  759.     ori.w    #$0700,sr    ; turn interrupts off
  760.  
  761. DO_WINDO:
  762.     bsr    CH_ZERO        ; and re-open as a CON
  763.     bsr    CH_KEYQ        ; get keyboard Q
  764.  
  765. REL_BAS:
  766.     move.l    a2,SV_KEYQ(a5)    ; make Q current
  767.  
  768.     sf    SV_SCRST(a5)    ; screen status
  769.  
  770.     bclr    #7,JB_RELA6(a4)
  771.  
  772.     move.w    JB_STAT(a4),d0    ; job status (BASIC)
  773.     beq.s    REL_BAS2     ; not suspended
  774.  
  775.     move.b    JB_PRINC(a4),d0    ; priority of BASIC
  776.     bne.s    REL_BAS1
  777.  
  778.     move.b    #$20,JB_PRINC(a4) ; if 0 set to 32
  779.  
  780. REL_BAS1:
  781.     clr.w    JB_STAT(a4)    ; release job
  782.     move.l    JB_HOLD(a4),d0    ; Ptr to byte to be
  783.                 ; cleared when job released
  784.     beq.s    REL_BAS2
  785.  
  786.     movea.l    d0,a3        ; clear this byte
  787.     sf    (a3)
  788.  
  789. REL_BAS2:
  790.     move.l    a6,JB_A6(a4)    ; save BASICs A6
  791.  
  792.     move.l    SV_TRNSP(a5),a3    ; get BASICs A7
  793.     clr.l    -(a3)
  794.     move.l    a3,JB_A7(a4)    ; and save it
  795.  
  796.     lea    L04B54(pc),a2    ; get Basic Warm start address
  797.     move.l    a2,JB_PC(a4)    ; set PC to WARM START address
  798.  
  799.     move.l    a2,-(a3)     ; save return address = basic warm start
  800.  
  801.     move.l    a3,usp
  802.  
  803.     sf    BV_BRK(a6)    ; signal Break to BASIC
  804.  
  805.     move.l    0,a7        ; reset supervisor stack
  806.  
  807. REL_JOB:
  808.     move.l    SV_JBPNT(a5),a3    ; current job table entry
  809.  
  810. JOB_LUP:
  811.     move.l    (a3),a2        ; current jobs' header
  812.     move.l    JB_OWNER(a2),d0    ; owner job
  813.     beq.s    REL_JOB1
  814.  
  815.     swap    d0
  816.     clr.w    d0
  817.     swap    d0
  818.     lsl.l    #2,d0
  819.     add.l    SV_JBBAS(a5),d0
  820.     move.l    d0,a3
  821.     bra.s    JOB_LUP
  822.  
  823. REL_JOB1:
  824.     move.l    a0,d5        ; save ch ID
  825.  
  826.     exg    a5,a6
  827.     bsr    JOBID_ME2
  828.     exg    a5,a6
  829.     move.l    d0,d1
  830.     beq.s    DEADX
  831.  
  832.     moveq    #ERR.NC,d3
  833.     moveq    #MT.FRJOB,d0
  834.     trap    #1        ; remove job
  835.  
  836.     move.l    d5,a0
  837.  
  838. DEADX:
  839.     move.w    #0,sr        ; user mode on
  840.     rts
  841.  
  842. NOTDEAD:
  843.  
  844. ; are next instructions about to be executed in single-trace mode?
  845.  
  846.     btst    #7,$40(a7)
  847.     beq.s    DSKIP        ; ...no, skip disassembly
  848.  
  849. ; if D68K_rext is loaded, print disassembly of next instruction
  850.  
  851.     lea    SV_THINGL(a5),a3    ; start of THING list
  852.  
  853. NEXT_THG:
  854.     move.l    (a3),d0
  855.     beq.s    DSKIP
  856.  
  857.     move.l    d0,a3
  858.  
  859.     cmp.w    #4,$2A(a3)
  860.     bne.s    NEXT_THG
  861.  
  862.     cmp.l    #'d68k',$2C(a3)    ; find d68k 'THING'
  863.     bne.s    NEXT_THG
  864.  
  865.     lea    TXTRTN(pc),a1
  866.     bsr    IOSTRG
  867.  
  868.     move.l    $10(a3),a3    ; address of data area
  869.     addq.l    #8,a3        ; a3 now points to 1st var
  870.  
  871.     move.l    a0,d5        ; save channel ID
  872.     move.l    $42(a7),a0    ; get pc
  873.     move.l    a0,a1        ; set org
  874.     move.l    4(a3),a2     ; address of buffer
  875.     move.l    a2,d4        ; save buffer address
  876.     addq.l    #2,a2
  877.     move.l    (a3),a3        ; address of routine
  878.  
  879.     jsr    (a3)        ; do it.
  880.  
  881.     move.l    d4,a1        ; buffer address
  882.     suba.l    a1,a2
  883.     move.l    a2,d2
  884.     subq.l    #3,d2        ; # bytes to print
  885.     move.w    d2,(a1)
  886.     move.l    d5,a0        ; restore channel ID
  887.     bsr    IOSTRG        ; print it
  888.  
  889. DSKIP:
  890.     bsr    CH_KEYQ        ; check chan has key Q
  891.  
  892.     bne.s    IPC9KEY        ; ...yup, wait for key
  893.  
  894. ; flush buffers if not a screen channel (disk thrash time!)
  895.  
  896. ;     moveq     #-1,d3         ; timeout
  897. ;     moveq     #FS.FLUSH,d0
  898. ;     trap     #3         ; flush buffers for channel
  899.  
  900.     bra.s    IPC9X        ; ...and don't wait for a key
  901.  
  902. ; wait for key press, then return from exception
  903.  
  904. IPC9KEY:
  905.     andi    #$F8FF,sr    ; enable interrupts
  906.  
  907. IPC9LUP:
  908.     moveq    #MT.IPCOM,d0
  909.     lea    IPC9(pc),a3
  910.     trap    #1
  911.     btst    #6,d1
  912.     bne.s    IPC9X        ; exit if <SPACE> key pressed
  913.  
  914.     cmp.w    #$24,d7
  915.     bne.s    IPC9LUP        ; branch back if not trace
  916.  
  917.     btst    #5,d1
  918.     beq.s    IPC9TST1     ; branch if not <\> key
  919.  
  920.     move.l    BV_CHBAS(a6),d4    ; get ptr to BASICs # table
  921.     move.l    0(a6,d4.l),d0    ; get ID for #0
  922.     blt.s    NO_PROBS     ; branch if #0 closed
  923.  
  924.     move.l    d0,a0
  925.     moveq    #IO.CLOSE,d0
  926.     trap    #2        ; close channel
  927.  
  928. NO_PROBS:
  929.     moveq    #-1,d1
  930.     lea    TNAME-ORG0,a0
  931.     moveq    #IO.DELET,d0
  932.     trap    #2
  933.     moveq    #-1,d1
  934.     moveq    #2,d3
  935.     lea    TNAME-ORG0,a0
  936.     moveq    #IO.OPEN,d0
  937.     trap    #2
  938.     move.l    a0,0(a6,d4.l)    ; put ID into #0
  939.     bra.s    IPC9X
  940.  
  941. IPC9TST1:
  942.     btst    #0,d1
  943.     beq.s    IPC9LUP        ; branch back if not <ENTER> key
  944.  
  945.     andi.w    #$3FFF,$40(a7)    ; clear trace bits
  946.  
  947.     lea    REGSTK,a3
  948.     move.w    $40(a7),4(a3)    ; signal REG store invalid
  949.  
  950. IPC9X:
  951.     move.b    d6,JB_RELA6(a4)    ; restore JOBs' RELA6 flag
  952.  
  953. TIDYUP:
  954.     movem.l    (a7)+,d0-d7/a0-a6
  955.     addq    #4,a7        ; restore regs
  956.  
  957.     rte            ; return from exception
  958.  
  959. ; --------------------------------------------------------------
  960. STK_REGS:
  961.     movem.l    d0-d7/a0-a6,-(a7)
  962.     move.l    $3C(a7),d1    ; get return address
  963.     move.w    $40(a7),d0    ; get sr
  964.     lea    $46(a7),a1    ; get old a7 for supervisor
  965.     btst    #13,d0        ; was user mode ?
  966.     bne.s    STKREG1
  967.     move.l    usp,a1        ; if so, get old usp
  968. STKREG1:
  969.     move.l    a1,$3C(a7)    ; stack old a7
  970.     move.l    d1,-(a7)     ; stack return address
  971.     rts
  972.  
  973. ; --------------------------------------------------------------
  974. REGPRT:
  975.     moveq    #7,d1
  976.  
  977. REGLPD:
  978.     tst.w    d3
  979.     bpl.s    REGPRD
  980.  
  981.     move.l    (a2),d0
  982.     cmp.l    (a3),d0
  983.     beq.s    REGSKP
  984.  
  985. REGPRD:
  986.     move.l    d2,a1
  987.     bsr    IOSTRG
  988.  
  989.     moveq    #7,d0
  990.     sub.w    d1,d0
  991.     bsr    HEX04
  992.  
  993.     lea    TXTEQU(pc),a1
  994.     bsr    IOSTRG
  995.  
  996.     move.l    (a2),d0
  997.     bsr    HEX20
  998.  
  999.     addq.l    #4,a1
  1000.     bsr    IOSTRG
  1001.  
  1002.     move.l    (a2),(a3)
  1003.  
  1004. REGSKP:
  1005.     addq.l    #4,a2
  1006.     addq.l    #4,a3
  1007.     dbra    d1,REGLPD
  1008.  
  1009.     rts
  1010.  
  1011. ;*/endoverlay
  1012. ; --------------------------------------------------------------
  1013. ;*/endfile
  1014.